﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ProgNetComponents.Design.Editors;
using System.Drawing.Design;
using ProgNetComponents.Design.TypeConverters;
using ProgNetComponents.Interfaces;

namespace ProgNetComponents.Classes
{ 
    /// <summary>
    /// Base class for INamedObject
    /// </summary>
    [TypeConverter(typeof(NamedObjectTypeConverter))]
    public class NamedObject : INamedObject
    {
        /// <summary>
        /// Creates NamedObject instance
        /// </summary>
        /// <param name="name">Name</param>
        /// <param name="value">Value</param>
        public NamedObject(string name , object value )
        {
            Name = name;
            Value = value;
        }
        /// <summary>
        /// Creates NamedObject instance
        /// </summary>
        public NamedObject() { }

        /// <summary>
        /// Gets or sets object Name
        /// </summary>
        [System.ComponentModel.NotifyParentProperty(true)]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets obejct Value
        /// </summary>
        [Editor(typeof(ObjectEditor), typeof(UITypeEditor))]
        [System.ComponentModel.NotifyParentProperty(true)]
        public object Value { get; set; }
        /// <summary>
        /// Returns object name
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Name;
        }
        /// <summary>
        /// Specifies if Name and Value are the same for this instance and obj. obj have to be NamedObject
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            bool eq = false;
            if (obj is NamedObject)
            {
                NamedObject n = obj as NamedObject;
                eq = n.Name.IsTheSame(Name);
                eq &= n.Value.IsTheSame(Value);
            }
            return eq;
        }
        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
